package com.block.account.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.block.account.model.dto.ChangeAmountDTO;
import com.block.account.service.IAccountInfoHisService;
import com.block.db.entity.AccountInfo;
import com.block.db.entity.AccountInfoHis;
import com.block.db.mapper.AccountInfoHisMapper;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * <p>
 * 总账户流水 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-08-26
 */
@Service
public class AccountInfoHisServiceImpl extends ServiceImpl<AccountInfoHisMapper, AccountInfoHis> implements IAccountInfoHisService {

    @Override
    public boolean saveAccountHis(BigDecimal currentAmount, AccountInfo accountInfo, ChangeAmountDTO changeAmountDTO) {

        AccountInfoHis accountInfoHis = new AccountInfoHis();
        accountInfoHis.setAccountId(accountInfo.getId());
        accountInfoHis.setAccountName(accountInfo.getName());
        accountInfoHis.setDateInfo(LocalDate.now().toString());
        accountInfoHis.setActionType(changeAmountDTO.getActionTypeEnum().getValue());
        accountInfoHis.setCurrentAmount(currentAmount);
        accountInfoHis.setOriginAmount(accountInfo.getTotalAmount());
        accountInfoHis.setChangeAmount(changeAmountDTO.getChangeAmount());
        accountInfoHis.setDataInfo(changeAmountDTO.getDataInfo());
        accountInfoHis.setRemarkInfo(changeAmountDTO.getRemarkInfo());
        accountInfoHis.setOperatorId(changeAmountDTO.getOperatorId());
        accountInfoHis.setOperatorName(changeAmountDTO.getOperatorName());

        boolean save = this.save(accountInfoHis);

        return save;
    }
}
